package com.slkj.shilixiaoyuanapp.view.dialog;

import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.view.base.BaseBottomDialog;

import butterknife.BindView;

/**
 * Created  on 2018-08-28
 *
 * @author 唐开阔
 * @describe
 */
public class SendCommentDialog  extends BaseBottomDialog {
    @BindView(R.id.et_comment)
    EditText etComment;
    @BindView(R.id.tv_send)
    TextView tvSend;
    OnSendListener mListener;
    String base_hint = "回复";
    String hint = base_hint + "TA...";
    @Override
    public int getLayoutRes(){
        return R.layout.dialog_edit_cmment;
    }
    @Override
    public void bindView(){
        etComment.requestFocus();
        etComment.setHint(hint);
        getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        tvSend.setOnClickListener(v -> {
            String comment = etComment.getText().toString();
            if (!TextUtils.isEmpty(comment)){
                mListener.send(comment);
                dismiss();
            }
        });
    }
    public static SendCommentDialog creat(OnSendListener listener) {
        SendCommentDialog dialog = new SendCommentDialog();
        dialog.mListener = listener;
        return dialog;
    }

    public interface OnSendListener {
        void send(String comment);
    }
    public void showHint(FragmentManager fragmentManager, String hint) {
        this.hint   = base_hint +  hint;
        show(fragmentManager, getFragmentTag());
    }

    @Override
    public void onDestroyView(){
        etComment.setText("");
        super.onDestroyView();
        hint = base_hint + "TA...";
    }
}
